//
//  CMDBPublicNoticeManager.swift
//  CMDB
//
//  Created by 王磊 on 17/4/7.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBPublicNoticeManager: NSObject {
    
    static let getInstance: CMDBPublicNoticeManager = CMDBPublicNoticeManager()
    
    private override init() {
        super.init()
        
    }
}
extension CMDBPublicNoticeManager: CMDBPublicNoticeManagerDelegate { }

extension CMDBPublicNoticeManager {
    
    func queryHomePublicNoticeList(publicNoticeListParam: CMDBPublicNoticeParam, tableView: UITableView, handler: CMDBPublicNoticeListHandler, error: CMDBHttpErrorHandler, failure: CMDBHttpFailureHandler) {
        
        printLog(publicNoticeListParam.keyValues)
        
        CMDBHttpManager.getInstance.request(publicNoticeListParam.URLString(), param: publicNoticeListParam.keyValues, ownPage: publicNoticeListParam.otype, tableView: tableView, success: { [weak self](sysTime, data, page) in
            
            let arr = CMDBPublicNoticeBean.objectArrayWithKeyValuesArray(data as! NSArray) as? Array<CMDBPublicNoticeBean>
            
            if let _ = arr where publicNoticeListParam.otype == 0 {
                
                //                self!.savePublicNoticeList(arr!, identifier: "CMDBHomeDynamicList_")
            }
            
            handler(publicNoticeList: arr)
            
            }, error: error, failure: failure)
        
        
    }
    func savePublicNoticeList(publicNotiList: Array<CMDBPublicNoticeBean>, identifier: String) {
        
        let mutable = NSMutableArray()
        
        _ = publicNotiList.map {
            
            mutable.addObject($0)
        }
        
        CMDBCacheDataManager.getInstance.saveArray(mutable, identifier: identifier)
        
    }
    
    func queryPublicNoticeListCache(identifier: String) throws -> Array<CMDBPublicNoticeBean> {
        
        return []
    }
    
}